package com.code.leetcode.idea;

public class LeetCodeIdea035 {
    public static void main(String[] args) {
        LeetCodeIdea035 leetCodeIdea035 = new LeetCodeIdea035();
        int[] nums = new int[]{1, 3, 5, 6};
        int target = 5;
        int res = leetCodeIdea035.searchInsert(nums, target);
        System.out.println(res);

    }
    public int searchInsert(int[] nums, int target) {
        if (nums.length == 0) {
            return 0;
        }
        int left = 0,right = nums.length - 1;

        while (left <= right) {

            int mid = (left + right)/2;
            System.out.println(left + "," + right + "," + mid);
            if (nums[mid] == target) {
//                System.out.println("===");
                return mid;
            } else if (nums[mid] > target) {
//                System.out.println(">>>");
                right = mid-1;
            } else {
//                System.out.println("<<<");
                left = mid+1;
            }
        }
        return left;
    }
}
